#pragma once
#include<vector>

class unionFindSet
{
public:
	unionFindSet(size_t sz = 1)
		:_ufs(sz,-1)
	{}
	void Union(int x,int y)
	{
		int rootX = findRoot(x);
		int rootY = findRoot(y);
		if (rootX == rootY) return;
		_ufs[rootX] += _ufs[rootY];
		_ufs[rootY] = rootX;
	}
	int findRoot(int x)
	{
		int root = x;
		while (_ufs[root] >= 0)
		{
			root = _ufs[root];
		}
		return root;
	}
	size_t size() const
	{
		size_t _count = 0;
		for (auto x : _ufs)
		{
			if (x <= 0) ++_count;
		}
		return _count;
	}
private:
	vector<int> _ufs;
};
